package com.example.myapplication.KeChengMingShiAdapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.myapplication.KeChengMingShiBean.MingShiRvXiTongBean;
import com.example.myapplication.R;

import java.util.ArrayList;
import java.util.List;

public class MingShiXiTongFuXIAdapter extends RecyclerView.Adapter<MingShiXiTongFuXIAdapter.HodlerView> {
    List<MingShiRvXiTongBean>list=new ArrayList<>();

    public MingShiXiTongFuXIAdapter(List<MingShiRvXiTongBean> list) {
        this.list = list;
    }
    static class HodlerView extends RecyclerView.ViewHolder{
        View view;
        ImageView img;
        TextView keshi,text1,text2,zhuangtai,name;

        public HodlerView(@NonNull View itemView) {
            super(itemView);
            view=itemView;
            img=view.findViewById(R.id.MingShi_img);
            keshi=view.findViewById(R.id.MingSHi_keshi);
            text1=view.findViewById(R.id.MingShi_text1);
            text2=view.findViewById(R.id.MingShi_text2);
            zhuangtai=view.findViewById(R.id.MingShi_zhuangtai);
            name=view.findViewById(R.id.MingShi_name);
        }
    }
    @NonNull
    @Override
    public HodlerView onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.mingshi_xitongfuxi_mokuai,parent,false);
        final HodlerView hodlerView=new HodlerView(view);
        hodlerView.img.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                int ponsition=hodlerView.getAdapterPosition();
                MingShiRvXiTongBean mingShiRvXiTongBean=list.get(ponsition);
                Toast.makeText(view.getContext(), mingShiRvXiTongBean.getName(), Toast.LENGTH_SHORT).show();
            }
        });
        return hodlerView;
    }

    @Override
    public void onBindViewHolder(@NonNull HodlerView holder, int position) {
        MingShiRvXiTongBean mingShiRvXiTongBean=list.get(position);
        holder.img.setImageResource(mingShiRvXiTongBean.getImg());
        holder.keshi.setText(mingShiRvXiTongBean.getKeshi());
        holder.text1.setText(mingShiRvXiTongBean.getText1());
        holder.text2.setText(mingShiRvXiTongBean.getText2());
        holder.zhuangtai.setText(mingShiRvXiTongBean.getZhuangtai());
        holder.name.setText(mingShiRvXiTongBean.getName());

    }

    @Override
    public int getItemCount() {
        return list.size();
    }




}
